package com.kai.mqtt.controller;

import com.kai.mqtt.data.PageResult;
import com.kai.mqtt.data.Result;
import com.kai.mqtt.data.request.PageSessionRequest;
import com.kai.mqtt.data.response.SessionResponse;
import com.kai.mqtt.session.service.ISessionService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author weijk
 * @since 2024/7/4
 */
@RestController
@RequestMapping("/session")
public class SessionController {

    @Resource
    private ISessionService sessionService;

    /**
     * 分页查询会话列表
     *
     * @param request 参数
     * @return 会话列表
     */
    @PostMapping("/page")
    public PageResult<SessionResponse> pageSession(@RequestBody PageSessionRequest request) {
        return sessionService.pageSession(request);
    }

    /**
     * 删除会话
     *
     * @param clientId 客户端 id
     * @return true-成功，false-失败
     */
    @DeleteMapping("/delete")
    public Result<Boolean> deleteSession(@RequestParam("clientId") String clientId) {
        return Result.success(sessionService.deleteSession(clientId));
    }
}
